package com.onefish.toolkit;

import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.pdmodel.PDPage;
import org.apache.pdfbox.pdmodel.PDPageContentStream;
import org.apache.pdfbox.pdmodel.font.PDType1Font;

import java.io.IOException;

public class CreateMultiPagePDF {
    public static void main(String[] args) {
        try (PDDocument document = new PDDocument()) {
            for (int i = 0; i < 5; i++) {
                PDPage page = new PDPage();
                document.addPage(page);

                try (PDPageContentStream contentStream = new PDPageContentStream(document, page)) {
                    contentStream.beginText();
                    contentStream.setFont(PDType1Font.HELVETICA, 12);
                    contentStream.newLineAtOffset(100, 700);
                    contentStream.showText("Page " + (i + 1));
                    contentStream.endText();
                }
            }

            document.save("multiPage.pdf");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}